$(function() {
	var $result = $('#events-result');
	var id = 0, getRows = function() {
		var rows = [];
		for ( var i = 0; i < 10; i++) {
			rows.push({
				id : id,
				fdWxOpenId : 'fdWxOpenId' + id,
				docCreateTime : 'docCreateTime' + id
			});
			id++;
		}
		return rows;
	},
	// init table use data
	$table = $('#events-table').bootstrapTable({
		data : getRows()
	});
	
	
	
	
	
	
	
	$('#refresh-data').click(function() {
		$table.bootstrapTable('refresh', {
			url : i1510.contextPath + "/admin/mflowUser/jqList.do"
		});
	});

	$('#download-data').click(function() {
		var selects = $table.bootstrapTable('getSelections');
		ids = $.map(selects, function(row) {
			return row.docId;
		});
		if (ids.length >= 1) {
			var data = new Object();
			data['docId'] = ids[0];
		    $.ajax({
				        url: i1510.contextPath+"/admin/mflowUser/searchWxUserInfo.do",
				        async: true,
				        dataType: 'json',
				        type: 'POST',
				        data: data,		
				        success: function(data , textStatus){
				        	if(data.result == "success"){
				        		$result.removeClass("alert-danger");
								$result.addClass("alert-info");
								$result.text("提示:获取更新成功!");
				        	}else{
				        		$result.removeClass("alert-info");
								$result.addClass("alert-danger");
								$result.text("提示:获取失败!");
				        	}
				        },		       
				        error: function(jqXHR , textStatus , errorThrown){
				        	window.location.href = "";
				        }
				       
			});
		}else{
			$result.removeClass("alert-info");
			$result.addClass("alert-danger");
			$result.text("提示:获取失败!");
		}
			
	
		
		$table.bootstrapTable('refresh', {
			url : i1510.contextPath + "/admin/mflowUser/jqList.do"
		});
		

	});
	
	$('#remove-data').click(function() {
		var selects = $table.bootstrapTable('getSelections');
		ids = $.map(selects, function(row) {
			return row.docId;
		});

		$table.bootstrapTable('remove', {
			field : 'docId',
			values : ids
		});

	});

	$('#get-selections').click(
			function() {
				alert('Selected values: '
						+ JSON
								.stringify($table
										.bootstrapTable('getSelections')));
			});
	$('#edit-data').click(
			function() {

				var selects = $table.bootstrapTable('getSelections');
				ids = $.map(selects, function(row) {
					return row.docId;
				});
				if (ids.length != 1) {
					$result.removeClass("alert-info");
					$result.addClass("alert-danger");
					$result.text("提示:只能选择一条数据进行修改!");
				} else {
					$result.removeClass("alert-danger");
					$result.addClass("alert-info");
					$result.text("提示!");
					window.open(i1510.contextPath
							+ "/wx/include/config/gzh_edit.jsp?id=" + ids[0],
							"gzh_edit");
				}
			});
	$('#add-data').click(
			function() {
				var selects = $table.bootstrapTable('getSelections');
				ids = $.map(selects, function(row) {
					return row.docId;
				});
				window.open(i1510.contextPath
						+ "/wx/include/config/gzh_edit.jsp", "gzh_add");
			});

	window.operateEvents = {
			 'click .openImg': function (e, value, row, index) {
					window.open(row.fdWxHeadImgUrl,"fdWxHeadImgUrl");
		           
		        },
	        'click .docStatusClass00': function (e, value, row, index) {
	        	var data = new Object();
				data['docId'] = row.docId;
				data['docStatus'] = "00";
	        	$.ajax({
				        url: i1510.contextPath+"/admin/mflowUser/updateStatus.do",
				        async: true,
				        dataType: 'json',
				        type: 'POST',
				        data: data,		
				        success: function(data , textStatus){
				        	if(data.result == "success"){
				        		$result.removeClass("alert-danger");
								$result.addClass("alert-info");
								$result.text("提示:获取更新成功!");
								$table.bootstrapTable('refresh', {
									url : i1510.contextPath + "/admin/mflowUser/jqList.do"
								});
				        	}else{
				        		$result.removeClass("alert-info");
								$result.addClass("alert-danger");
								$result.text("提示:获取失败!");
				        	}
				        },		       
				        error: function(jqXHR , textStatus , errorThrown){
				        	window.location.href = "";
				        }
				       
	        	});
	            
	           
	        },

	        'click .docStatusClass10': function (e, value, row, index) {
	        	var data = new Object();
				data['docId'] = row.docId;
				data['docStatus'] = "10";
	        	$.ajax({
				        url: i1510.contextPath+"/admin/mflowUser/updateStatus.do",
				        async: true,
				        dataType: 'json',
				        type: 'POST',
				        data: data,		
				        success: function(data , textStatus){
				        	if(data.result == "success"){
				        		$result.removeClass("alert-danger");
								$result.addClass("alert-info");
								$result.text("提示:获取更新成功!");
								$table.bootstrapTable('refresh', {
									url : i1510.contextPath + "/admin/mflowUser/jqList.do"
								});
				        	}else{
				        		$result.removeClass("alert-info");
								$result.addClass("alert-danger");
								$result.text("提示:获取失败!");
				        	}
				        },		       
				        error: function(jqXHR , textStatus , errorThrown){
				        	window.location.href = "";
				        }
				       
	        	});
	            
	           
	        },

	        'click .docStatusClass20': function (e, value, row, index) {
	        	var data = new Object();
				data['docId'] = row.docId;
				data['docStatus'] = "20";
	        	$.ajax({
				        url: i1510.contextPath+"/admin/mflowUser/updateStatus.do",
				        async: true,
				        dataType: 'json',
				        type: 'POST',
				        data: data,		
				        success: function(data , textStatus){
				        	if(data.result == "success"){
				        		$result.removeClass("alert-danger");
								$result.addClass("alert-info");
								$result.text("提示:获取更新成功!");
								$table.bootstrapTable('refresh', {
									url : i1510.contextPath + "/admin/mflowUser/jqList.do"
								});
				        	}else{
				        		$result.removeClass("alert-info");
								$result.addClass("alert-danger");
								$result.text("提示:获取失败!");
				        	}
				        },		       
				        error: function(jqXHR , textStatus , errorThrown){
				        	window.location.href = "";
				        }
				       
	        	});
	            
	           
	        }
	    };

});
function fmt_docStatus(value, row, index) {
	if(value == '00'){
		return [
	            '<a class="docStatusClass10" href="javascript:void(0)" >',
	                '<i class="icon-retweet"></i>启用',
	            '</a>',
	            '<a class="openImg" href="javascript:void(0)" target="_blank">',
	                '<i class="icon-zoom-out"></i>查看图片',
	            '</a>'
	        ].join('');
	}else if(value == '10'){
		return [
	            '<a class="docStatusClass00"  href="javascript:void(0)" >',
	                '<i class="icon-retweet" ></i>废弃',
	            '</a>',
	            '<a class="docStatusClass20" href="javascript:void(0)" >',
                	'<i class="icon-retweet"></i>绑定',
                '</a>',
	            '<a class="openImg" href="javascript:void(0)" target="_blank">',
	                '<i class="icon-zoom-out"></i>查看图片',
	            '</a>'
	        ].join('');
		
	}else if(value == '20'){
		return [
	            '<a class="docStatusClass00" href="javascript:void(0)" >',
	                '<i class="icon-retweet" ></i>废弃',
	            '</a>',
	            '<a class="docStatusClass10" href="javascript:void(0)" >',
                	'<i class="icon-retweet"></i>解除绑定',
                '</a>',
	            '<a class="openImg" href="javascript:void(0)" target="_blank">',
                	'<i class="icon-zoom-out"></i>查看图片',
                '</a>'
	        ].join('');
		
	}
	
}
